package com.xgg.taiwuinfo.filter.fc;

import android.util.Log;

import com.xgg.taiwuinfo.filter.FC_SelectCompareSelect;
import com.xgg.taiwuinfo.filter.FilterComponent;
import com.xgg.taiwuinfo.gongfa.abilities.Ability_Cuipo_Hit;
import com.xgg.taiwuinfo.gongfa.base.Gongfa;
import com.xgg.taiwuinfo.gongfa.base.Gongfa_Cuipo;
import com.xgg.taiwuinfo.utils.GongfaType;

import org.json.JSONObject;

import java.util.ArrayList;

public class FCCuipoHitCompareSelect extends FC_SelectCompareSelect {
    public FCCuipoHitCompareSelect(JSONObject obj)
    {
        mTypeId = FilterComponent.FT_CUIPOHIT_COMPARE_SELECT;
        if (obj != null) {
            try {
                ReadField = obj.getInt("f");
                ReadCompare = obj.getInt("c");
                ReadValue = obj.getInt("v");
            } catch (Exception e) {
                Log.d("LoadJson", e.getLocalizedMessage());
                ReadField = 0;
                ReadCompare = FC_GREATER;
                ReadValue = 0;
            }
        }
        else {
            ReadField = 0;
            ReadCompare = FC_GREATER;
            ReadValue = 0;
        }
        TempField = ReadField;
        TempValue = ReadValue;
        TempCompare = ReadCompare;

        if (mFieldMap == null) {
            mFieldMap = new ArrayList<>();
            AddMap(mFieldMap, "最大命中分布", "0");
        }

        if (mValueMap == null) {
            mValueMap = new ArrayList<>();
            AddMap(mValueMap , "四成" , "4");
            AddMap(mValueMap , "五成" , "5");
            AddMap(mValueMap , "六成" , "6");
            AddMap(mValueMap , "七成" , "7");
            AddMap(mValueMap , "八成" , "8");
            AddMap(mValueMap , "九成" , "9");
            AddMap(mValueMap , "十成" , "10");
        }

        if (mCompMap == null)
        {
            mCompMap = new ArrayList<>();
        }
        else
        {
            mCompMap.clear();
        }
        AddMap(mCompMap , "高于" , FC_GREATER + "");
        AddMap(mCompMap , "不低于" , FC_GREATERCONTAIN + "");
        AddMap(mCompMap , "等于" , FC_EQUAL + "");
        AddMap(mCompMap , "不高于" , FC_SMALLERCONTAIN + "");
        AddMap(mCompMap , "低于" , FC_SMALLER + "");
    }

    @Override
    public String FilterGongfa(Gongfa gongfa){
        int type = gongfa.getType();
        Ability_Cuipo_Hit dmg = null;
        if ((type & GongfaType.TYPE_CUIPO) > 0) {
            dmg = ((Gongfa_Cuipo)gongfa).ability_cuipo_hit;
        }
        else
            return null;

        int gfvalue = 0;        //功法内数据
        int edvalue = ReadValue;        //用户填写的数据
        gfvalue = dmg.mJM > dmg.mLD ? dmg.mJM : dmg.mLD;
        gfvalue = gfvalue > dmg.mXJ ? gfvalue : dmg.mXJ;
        String rt = String.format("最大命中分布: %d" , gfvalue);
        switch (ReadCompare)
        {
            case FC_EQUAL:
                if (gfvalue == edvalue) {
                    return rt;
                }
                else{
                    return null;
                }
            case FC_GREATER:
                if (gfvalue > edvalue) {
                    return rt;
                }
                else{
                    return null;
                }
            case FC_GREATERCONTAIN:
                if (gfvalue >= edvalue) {
                    return rt;
                }
                else {
                    return null;
                }
            case FC_SMALLER:
                if (gfvalue < edvalue && gfvalue > 0) {
                    return rt;
                }
                else{
                    return null;
                }
            case FC_SMALLERCONTAIN:
                if (gfvalue <= edvalue && gfvalue > 0) {
                    return rt;
                }
                else {
                    return null;
                }
            default:
                return null;
        }
    }
}
